﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class FormCalc : FormBase
    {
        string strNum1 = null;
        string strOp = null;
        string strExpress = null;
        public FormCalc()
        {
            InitializeComponent();
        }

        public FormCalc(ToolStripMenuItem tsMi): base(tsMi)
        {
            InitializeComponent();
        }

        private void btnNum_Click(object sender, EventArgs e)
        {
            if (strNum1 == null)
            {
                strNum1 = tbNum.Text;
                tbNum.Text = "";
            }
            if (sender is Button)
            {
                Button btn = sender as Button;   //as === (Button)sender
                tbNum.Text = tbNum.Text + btn.Text;
                strExpress = strExpress + tbNum.Text;
                textBox1.Text = strExpress;
            }
        }

        private void btnOp_Click(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                Button btn = sender as Button;
                if (strNum1 == null)
                {
                    strOp = btn.Text;
                    strNum1 = tbNum.Text;
                    tbNum.Text = "";
                }
                else
                {
                    switch (strOp)
                    {
                        case "+":
                            tbNum.Text = (int.Parse(strNum1) + int.Parse(tbNum.Text)).ToString();
                            break;
                        case "*":
                            tbNum.Text = (int.Parse(strNum1) * int.Parse(tbNum.Text)).ToString();
                            break;
                    }
                    strNum1 = null;
                    strOp = btn.Text;
                }
                strExpress = strExpress + strOp;
                textBox1.Text = strExpress;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (strOp == "*")
            {
                tbNum.Text = (int.Parse(strNum1) * int.Parse(tbNum.Text)).ToString();
            }
        }
    }
}
